package com.zlkj.pro.modular.common.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.zlkj.pro.core.consts.ProjectConstants;
import com.zlkj.pro.modular.common.service.UploadCommonService;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author yz
 * @date 2022/04/27 10:07
 */
@RestController
@ApiResource(path = ProjectConstants.SERVICE_API_PREFIX + "/common", name = "公共方法")
public class CommonApiController {

    @Resource
    private UploadCommonService uploadCommonService;

    /**
     * 上传文件
     *
     * @author yz
     * @date 2022/04/27 10:07
     */
    @PostResource(name = "上传文件", path = "/fileInfo/upload", requiredPermission = false, requiredLogin = false)
    public ResponseData upload(@RequestPart("file") MultipartFile file) throws IOException {
        //                               @RequestPart("dir") String dir
        String s = "";
        try {
            s = uploadCommonService.uploadMinioFile(file);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new SuccessResponseData(s);
    }


}
